package com.goldcn.util;

import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;

/**
 * Created by Administrator on 2017/7/19.
 */
public class PinyinUtil {

   /* String str = "你好世界";
    PinyinHelper.convertToPinyinString(str, ",", PinyinFormat.WITH_TONE_MARK); // nǐ,hǎo,shì,jiè
    PinyinHelper.convertToPinyinString(str, ",", PinyinFormat.WITH_TONE_NUMBER); // ni3,hao3,shi4,jie4
    PinyinHelper.convertToPinyinString(str, ",", PinyinFormat.WITHOUT_TONE); // ni,hao,shi,jie
    PinyinHelper.getShortPinyin(str); // nhsj
    PinyinHelper.addPinyinDict("user.dict");  // 添加用户自定义字典*/

    public static String cn2Spell(String chinaese){
        try {
            return PinyinHelper.convertToPinyinString(chinaese, "", PinyinFormat.WITHOUT_TONE);
        } catch (PinyinException e) {
            return chinaese;
        }
    }


    public static String cn2Spell(String chinaese,boolean isShortPinyin){
        try {
            return PinyinHelper.getShortPinyin(chinaese);
        } catch (PinyinException e) {
            return chinaese;
        }
    }

}
